import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:wallet_utils/color.dart';
import 'package:wallet_utils/report_widget/click_widget.dart';

/// @author: pengboboer
/// @createDate: 2022/1/25
class CommonActionSheetDialog extends StatelessWidget {
  final List<String> list;
  final ValueChanged<String> onConfirm;

  const CommonActionSheetDialog(
      {Key? key, required this.list, required this.onConfirm})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
        borderRadius: BorderRadius.only(
            topLeft: Radius.circular(12.w),
            topRight: Radius.circular(12.w)),
      child: Container(
        color: Colors.white,
        padding: EdgeInsets.only(bottom: ScreenUtil().bottomBarHeight),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            ...List.generate(list.length,
                (index) => _buildItem(index, index != list.length - 1)),
            Container(color: ColorManager.colorFAFAFA, height: 10.w),
            _buildCancelWidget()
          ],
        ),
      ),
    );
  }

  Widget _buildItem(int index, bool isShowGrayLine) {
    return ClickWidget(
      onTap: () {
        onConfirm(list[index]);
      },
      child: Container(
        alignment: Alignment.center,
        child: Column(
          children: [
            Container(
              height: 52.w,
              alignment: Alignment.center,
              child: Text(
                list[index],
                style: TextStyle(
                  fontSize: 16.sp,
                  color: ColorManager.color2A2A2A,
                ),
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
              ),
            ),
            Visibility(
              visible: isShowGrayLine,
              child: Container(
                margin: EdgeInsets.symmetric(horizontal: 16.w),
                height: 0.5.w,
                color: ColorManager.colorF4F4F4,
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildCancelWidget() {
    return ClickWidget(
      onTap: () => Get.back(),
      child: Container(
        alignment: Alignment.center,
        child: Column(
          children: [
            Container(
              height: 52.w,
              alignment: Alignment.center,
              child: Text(
                "取消",
                style: TextStyle(
                  fontSize: 16.sp,
                  color: ColorManager.color999999,
                ),
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
              ),
            ),
            Visibility(
              visible: false,
              child: Container(
                margin: EdgeInsets.symmetric(horizontal: 16.w),
                height: 0.5.w,
                color: ColorManager.colorF4F4F4,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
